package com.ruoyi.thirdpartyaccounts.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.thirdpartyaccounts.domain.Thirdpartyaccounts;
import com.ruoyi.thirdpartyaccounts.service.IThirdpartyaccountsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 第三方账号Controller
 * 
 * @author ruoyi
 * @date 2024-06-28
 */
@RestController
@RequestMapping("/thirdpartyaccounts/thirdpartyaccounts")
public class ThirdpartyaccountsController extends BaseController
{
    @Autowired
    private IThirdpartyaccountsService thirdpartyaccountsService;

    /**
     * 查询第三方账号列表
     */
    @PreAuthorize("@ss.hasPermi('thirdpartyaccounts:thirdpartyaccounts:list')")
    @GetMapping("/list")
    public TableDataInfo list(Thirdpartyaccounts thirdpartyaccounts)
    {
        startPage();
        List<Thirdpartyaccounts> list = thirdpartyaccountsService.selectThirdpartyaccountsList(thirdpartyaccounts);
        return getDataTable(list);
    }

    /**
     * 导出第三方账号列表
     */
    @PreAuthorize("@ss.hasPermi('thirdpartyaccounts:thirdpartyaccounts:export')")
    @Log(title = "第三方账号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Thirdpartyaccounts thirdpartyaccounts)
    {
        List<Thirdpartyaccounts> list = thirdpartyaccountsService.selectThirdpartyaccountsList(thirdpartyaccounts);
        ExcelUtil<Thirdpartyaccounts> util = new ExcelUtil<Thirdpartyaccounts>(Thirdpartyaccounts.class);
        util.exportExcel(response, list, "第三方账号数据");
    }

    /**
     * 获取第三方账号详细信息
     */
    @PreAuthorize("@ss.hasPermi('thirdpartyaccounts:thirdpartyaccounts:query')")
    @GetMapping(value = "/{thirdPartyId}")
    public AjaxResult getInfo(@PathVariable("thirdPartyId") Long thirdPartyId)
    {
        return success(thirdpartyaccountsService.selectThirdpartyaccountsByThirdPartyId(thirdPartyId));
    }

    /**
     * 新增第三方账号
     */
    @PreAuthorize("@ss.hasPermi('thirdpartyaccounts:thirdpartyaccounts:add')")
    @Log(title = "第三方账号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Thirdpartyaccounts thirdpartyaccounts)
    {
        return toAjax(thirdpartyaccountsService.insertThirdpartyaccounts(thirdpartyaccounts));
    }

    /**
     * 修改第三方账号
     */
    @PreAuthorize("@ss.hasPermi('thirdpartyaccounts:thirdpartyaccounts:edit')")
    @Log(title = "第三方账号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Thirdpartyaccounts thirdpartyaccounts)
    {
        return toAjax(thirdpartyaccountsService.updateThirdpartyaccounts(thirdpartyaccounts));
    }

    /**
     * 删除第三方账号
     */
    @PreAuthorize("@ss.hasPermi('thirdpartyaccounts:thirdpartyaccounts:remove')")
    @Log(title = "第三方账号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{thirdPartyIds}")
    public AjaxResult remove(@PathVariable Long[] thirdPartyIds)
    {
        return toAjax(thirdpartyaccountsService.deleteThirdpartyaccountsByThirdPartyIds(thirdPartyIds));
    }
}
